<?php 

$ch = curl_init('http://m.avito.ru/captcha?1382477848');
$fp = fopen('./images/logo1.png', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_REFERER, 'http://m.avito.ru/add/confirm');
//curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_COOKIEJAR,$_SERVER['DOCUMENT_ROOT'].'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE,$_SERVER['DOCUMENT_ROOT'].'/cookie.txt');
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
//curl_setopt ($ch, CURLOPT_VERBOSE, 2); // Отображать детальную информацию о соединении
//curl_setopt ($ch, CURLOPT_ENCODING, 0);
//curl_setopt($ch, CURLOPT_TIMEOUT, 10);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
///var_dump($_COOKIE);
$hdr=array(
		'User-Agent: BlackBerry9530/4.7 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/105',
		'Accept: image/png,image/*;q=0.8,*/*;q=0.5',
		'Host m.avito.ru',
		'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3',
		'Accept-Encoding: gzip, deflate',
		'Connection: keep-alive',

);

curl_setopt($ch, CURLOPT_HTTPHEADER,$hdr);
$result = curl_exec($ch);
var_dump(curl_getinfo($ch, CURLINFO_HEADER_OUT));
//var_dump(curl_getinfo($ch));
//$html = str_replace('/captcha?','http://m.avito.ru/captcha?',$html);
//$html = str_replace('form action="/add/confirm"','form action="http://m.avito.ru/add/confirm"',$html);
//echo curl_error($ch);
var_dump($result);


//curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
